using System.Web.Mvc;
using Dnf.Tools.Sugar;

namespace KickStart.Controllers
{
    public class SugarController : Controller
    {
        //
        // GET: /Sugar/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Bitly(string longUrl)
        {
            if (string.IsNullOrEmpty(longUrl))
            {
                ModelState.AddModelError("longurl", "Url is required");
            }
            if (ModelState.IsValid)
            {
                var result = BitlyApi.ShortenUrl(longUrl);
                ViewData["shorturl"] = result.ShortUrl;
            }
            return View("index");
        }
    }
}
